package org.song.listprocess.database;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

public class JFileOption {
	public static boolean write(String filename,byte[] bytes){
		File file = new File(filename);
		try {
			if(file.exists()){//override file
				file.delete();
				file.createNewFile();
			}
			FileOutputStream os = new FileOutputStream(file);
			os.write(bytes);//toString is pack list function
			os.close();
			return true;
		} catch (IOException e) {
			// TODO Auto-generated catch block
			System.out.println(e.getMessage());
			return false;
		}
	}
	
	public static byte[] read(String filename){
		File file = new File(filename);
		byte[] bytes = new byte[(int)file.length()];
		try{
			FileInputStream is = new FileInputStream(file);			
			is.read(bytes);
			is.close();
		}catch(IOException e){
			System.out.println(e.getMessage());
			return null;
		}
		return bytes;
	}
}
